<?php
class TModel
{
	/* ConnectDBName */
	/* MySQL,PostgreSQL */
	protected $db = '';

	public function __construct($c){
		$this->controller = $c;
		$files = scandir(PLUGIN_DIR.'/TDB');
		if($this->db != '' && array_search('T'.$this->db.'.php', $files) !== false){
			$this->getConnection();
		}
	}

	protected function getConnection(){
		require_once(PLUGIN_DIR.'/TDB/TDB.php');
		require_once(PLUGIN_DIR.'/TDB/T'.$this->db.'.php');
		$dbi = new $this->db;
		$i = new TDB($dbi);
		$this->{$this->db} = $i;
	}

	public function begin(){
		$this->{$this->db}->beginTransaction();
		
	}
	public function commit(){
		$this->{$this->db}->commit();
	}
	public function rollback(){
		$this->{$this->db}->rollback();
	}
	public function useDB(){
		return ($this->db != '');
	}
}
